package com.fancy.learncenter.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.activity.PersonInfoActivity;
import com.fancy.learncenter.activity.ToothDetailsActivity;
import com.fancy.learncenter.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.adapter.base.CustomViewHold;
import com.fancy.learncenter.bean.CommentsDataBean;
import com.superservice.lya.R;

import java.util.ArrayList;

/**
 * Created by hyy on 2018/1/27.
 * Explain activity as
 */

public class PingLunAdapter extends CommonRecycleViewAdapter<CommentsDataBean> {

    public PingLunAdapter(Context mContext, ArrayList<CommentsDataBean> itemDatas) {
        super(mContext, R.layout.jinghuatie_pl_item, itemDatas);
    }

    boolean isSolveShow = false;

    public PingLunAdapter(Context mContext, ArrayList<CommentsDataBean> itemDatas, boolean isSolveShow) {
        super(mContext, R.layout.jinghuatie_pl_item, itemDatas);
        this.isSolveShow = isSolveShow;
    }

    @Override
    public void bindView(CustomViewHold customViewHold, final CommentsDataBean item, final int position) {

        SimpleDraweeView simpleDraweeView = customViewHold.getView(R.id.answer_icon);
        simpleDraweeView.setImageURI(item.getComment_user_img());

        simpleDraweeView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, PersonInfoActivity.class);
                intent.putExtra("userId", "" + item.getComment_user_id());
                mContext.startActivity(intent);
            }
        });

        TextView answer_name = customViewHold.getView(R.id.answer_name);
        answer_name.setText(item.getComment_user_name());

        TextView content = customViewHold.getView(R.id.content);
        content.setText(item.getContent());

        TextView time = customViewHold.getView(R.id.time);
        time.setText(item.getAdd_time());


        if (isSolveShow) {
            TextView solve = customViewHold.getView(R.id.solve);
            solve.setVisibility(View.VISIBLE);

            if (item.getStatus().equals("1")) {
                solve.setText("已采纳");
                solve.setBackgroundColor(Color.parseColor("#fda712"));
                solve.setTextColor(Color.parseColor("#FFFFFF"));
            } else {
                solve.setText("采纳");
                solve.setBackgroundResource(R.drawable.shape_line_orange);
                solve.setTextColor(Color.parseColor("#fda712"));
            }

            solve.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    solveOnClickCallBack.solveOnClick(position);
                }
            });
        }


        RecyclerView recyclerView = customViewHold.getView(R.id.recycleView);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);

        if (item.getReply() != null && item.getReply().size() > 0) {
            recyclerView.setVisibility(View.VISIBLE);
            recyclerView.setAdapter(new CommonRecycleViewAdapter<CommentsDataBean.ReplyBean>(mContext, R.layout.comments_msg_item, (ArrayList<CommentsDataBean.ReplyBean>) item.getReply()) {
                @Override
                public void bindView(CustomViewHold customViewHold, CommentsDataBean.ReplyBean item, int position) {

                    TextView content = customViewHold.getView(R.id.content);
                    content.setText(item.getReply());

                }
            });
        } else {
            recyclerView.setVisibility(View.GONE);
        }


        customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (onClickCallBack != null) {
                    onClickCallBack.OnClick(position);
                }
            }
        });
    }

    private OnClickCallBack onClickCallBack;

    public OnClickCallBack getOnClickCallBack() {
        return onClickCallBack;
    }

    public void setOnClickCallBack(OnClickCallBack onClickCallBack) {
        this.onClickCallBack = onClickCallBack;
    }

    public interface OnClickCallBack {
        abstract void OnClick(int position);
    }

    public SolveOnClickCallBack getSolveOnClickCallBack() {
        return solveOnClickCallBack;
    }

    public void setSolveOnClickCallBack(SolveOnClickCallBack solveOnClickCallBack) {
        this.solveOnClickCallBack = solveOnClickCallBack;
    }

    private SolveOnClickCallBack solveOnClickCallBack;

    public interface SolveOnClickCallBack {
        abstract void solveOnClick(int position);
    }
}
